home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / GameCreators / TADS / manuals / TEX / TADSOOP.TEX < prev    next >
LaTeX Document  |  1992-11-13  |  8.4 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: TADSOOP.TEX

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document, ASCII text, with CRLF line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried x-fmt/111 Plain Text File default
100% detectItEasy Format: plain text[CRLF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 20 24 48 65 61 64 65 | 72 3a 20 63 3a 2f 74 61 |% $Heade|r: c:/ta|
|00000010| 64 73 2f 64 6f 63 2f 52 | 43 53 2f 74 61 64 73 6f |ds/doc/R|CS/tadso|
|00000020| 6f 70 2e 74 65 78 20 31 | 2e 32 20 39 32 2f 31 31 |op.tex 1|.2 92/11|
|00000030| 2f 31 33 20 31 36 3a 34 | 35 3a 32 34 20 6d 72 6f |/13 16:4|5:24 mro|
|00000040| 62 65 72 74 73 20 45 78 | 70 20 24 0d 0a 25 20 54 |berts Ex|p $..% T|
|00000050| 41 44 53 20 44 6f 63 75 | 6d 65 6e 74 61 74 69 6f |ADS Docu|mentatio|
|00000060| 6e 2c 20 43 68 61 70 74 | 65 72 20 54 77 6f 3a 20 |n, Chapt|er Two: |
|00000070| 20 41 62 6f 75 74 20 4f | 62 6a 65 63 74 2d 4f 72 | About O|bject-Or|
|00000080| 69 65 6e 74 65 64 20 50 | 72 6f 67 72 61 6d 6d 69 |iented P|rogrammi|
|00000090| 6e 67 0d 0a 25 0d 0a 25 | 20 43 6f 70 79 72 69 67 |ng..%..%| Copyrig|
|000000a0| 68 74 20 28 63 29 20 31 | 39 38 39 20 62 79 20 4d |ht (c) 1|989 by M|
|000000b0| 69 63 68 61 65 6c 20 4a | 2e 20 52 6f 62 65 72 74 |ichael J|. Robert|
|000000c0| 73 2e 20 20 41 6c 6c 20 | 52 69 67 68 74 73 20 52 |s. All |Rights R|
|000000d0| 65 73 65 72 76 65 64 2e | 0d 0a 25 0d 0a 0d 0a 5c |eserved.|..%....\|
|000000e0| 63 68 61 70 74 65 72 68 | 65 61 64 65 72 7b 43 68 |chapterh|eader{Ch|
|000000f0| 61 70 74 65 72 20 54 77 | 6f 7d 7b 4f 62 6a 65 63 |apter Tw|o}{Objec|
|00000100| 74 2d 4f 72 69 65 6e 74 | 65 64 20 50 72 6f 67 72 |t-Orient|ed Progr|
|00000110| 61 6d 6d 69 6e 67 7d 7b | 32 7d 0d 0a 0d 0a 53 6f |amming}{|2}....So|
|00000120| 6d 65 77 68 65 72 65 20 | 61 72 6f 75 6e 64 20 31 |mewhere |around 1|
|00000130| 39 38 35 2c 20 74 68 65 | 20 73 6f 66 74 77 61 72 |985, the| softwar|
|00000140| 65 20 6d 61 72 6b 65 74 | 69 6e 67 20 63 6f 6d 6d |e market|ing comm|
|00000150| 75 6e 69 74 79 20 64 69 | 73 63 6f 76 65 72 65 64 |unity di|scovered|
|00000160| 20 74 68 65 0d 0a 74 65 | 72 6d 20 60 60 6f 62 6a | the..te|rm ``obj|
|00000170| 65 63 74 20 6f 72 69 65 | 6e 74 65 64 2c 27 27 20 |ect orie|nted,'' |
|00000180| 61 6e 64 20 6c 61 74 63 | 68 65 64 20 6f 6e 74 6f |and latc|hed onto|
|00000190| 20 74 68 65 20 70 68 72 | 61 73 65 20 77 69 74 68 | the phr|ase with|
|000001a0| 20 61 20 64 65 76 6f 74 | 69 6f 6e 0d 0a 74 68 61 | a devot|ion..tha|
|000001b0| 74 20 65 76 65 6e 20 60 | 60 68 79 70 65 72 74 65 |t even `|`hyperte|
|000001c0| 78 74 27 27 20 61 6e 64 | 20 60 60 6d 75 6c 74 69 |xt'' and| ``multi|
|000001d0| 2d 6d 65 64 69 61 27 27 | 20 68 61 76 65 20 79 65 |-media''| have ye|
|000001e0| 74 20 74 6f 20 61 70 70 | 72 6f 61 63 68 2e 0d 0a |t to app|roach...|
|000001f0| 57 69 74 68 20 73 6f 20 | 6d 61 6e 79 20 6d 61 72 |With so |many mar|
|00000200| 6b 65 74 65 72 73 20 75 | 73 69 6e 67 20 74 68 65 |keters u|sing the|
|00000210| 20 74 65 72 6d 2c 20 61 | 6e 64 20 73 6f 20 66 65 | term, a|nd so fe|
|00000220| 77 20 6b 6e 6f 77 69 6e | 67 20 77 68 61 74 20 69 |w knowin|g what i|
|00000230| 74 0d 0a 6d 65 61 6e 73 | 2c 20 60 60 6f 62 6a 65 |t..means|, ``obje|
|00000240| 63 74 20 6f 72 69 65 6e | 74 65 64 27 27 20 68 61 |ct orien|ted'' ha|
|00000250| 73 20 63 6f 6d 65 20 74 | 6f 20 6d 65 61 6e 20 61 |s come t|o mean a|
|00000260| 6c 6d 6f 73 74 20 61 6e | 79 74 68 69 6e 67 2c 20 |lmost an|ything, |
|00000270| 61 6e 64 0d 0a 68 65 6e | 63 65 20 6e 6f 74 68 69 |and..hen|ce nothi|
|00000280| 6e 67 2e 0d 0a 0d 0a 44 | 65 73 70 69 74 65 20 74 |ng.....D|espite t|
|00000290| 68 65 20 63 6f 6e 66 75 | 73 69 6f 6e 2c 20 74 68 |he confu|sion, th|
|000002a0| 65 20 74 65 72 6d 20 72 | 65 61 6c 6c 79 20 64 6f |e term r|eally do|
|000002b0| 65 73 20 68 61 76 65 20 | 61 20 6d 65 61 6e 69 6e |es have |a meanin|
|000002c0| 67 2e 0d 0a 54 68 69 73 | 20 73 65 63 74 69 6f 6e |g...This| section|
|000002d0| 20 77 69 6c 6c 20 61 74 | 74 65 6d 70 74 20 74 6f | will at|tempt to|
|000002e0| 20 63 6c 61 72 69 66 79 | 20 77 68 61 74 20 6f 62 | clarify| what ob|
|000002f0| 6a 65 63 74 2d 6f 72 69 | 65 6e 74 65 64 20 70 72 |ject-ori|ented pr|
|00000300| 6f 67 72 61 6d 6d 69 6e | 67 0d 0a 69 73 20 61 6e |ogrammin|g..is an|
|00000310| 64 20 68 6f 77 20 69 74 | 20 61 70 70 6c 69 65 73 |d how it| applies|
|00000320| 20 74 6f 20 54 41 44 53 | 2e 20 20 54 68 69 73 20 | to TADS|. This |
|00000330| 63 68 61 70 74 65 72 20 | 77 69 6c 6c 20 61 6c 73 |chapter |will als|
|00000340| 6f 20 65 78 70 6c 61 69 | 6e 20 77 68 79 20 61 6e |o explai|n why an|
|00000350| 0d 0a 6f 62 6a 65 63 74 | 2d 6f 72 69 65 6e 74 65 |..object|-oriente|
|00000360| 64 20 6c 61 6e 67 75 61 | 67 65 20 69 73 20 64 65 |d langua|ge is de|
|00000370| 73 69 72 61 62 6c 65 20 | 77 68 65 6e 20 77 72 69 |sirable |when wri|
|00000380| 74 69 6e 67 20 61 64 76 | 65 6e 74 75 72 65 73 2e |ting adv|entures.|
|00000390| 0d 0a 0d 0a 54 68 69 73 | 20 73 65 63 74 69 6f 6e |....This| section|
|000003a0| 20 69 73 20 6e 6f 74 20 | 60 60 72 65 71 75 69 72 | is not |``requir|
|000003b0| 65 64 20 72 65 61 64 69 | 6e 67 22 20 69 6e 20 6c |ed readi|ng" in l|
|000003c0| 65 61 72 6e 69 6e 67 20 | 54 41 44 53 2c 20 62 75 |earning |TADS, bu|
|000003d0| 74 20 69 74 20 6d 61 79 | 20 68 65 6c 70 0d 0a 79 |t it may| help..y|
|000003e0| 6f 75 20 75 6e 64 65 72 | 73 74 61 6e 64 20 73 6f |ou under|stand so|
|000003f0| 6d 65 20 6f 66 20 74 68 | 65 20 67 65 6e 65 72 61 |me of th|e genera|
|00000400| 6c 20 69 64 65 61 73 20 | 74 68 61 74 20 69 6e 66 |l ideas |that inf|
|00000410| 6c 75 65 6e 63 65 64 20 | 74 68 65 20 64 65 73 69 |luenced |the desi|
|00000420| 67 6e 20 6f 66 0d 0a 74 | 68 65 20 73 79 73 74 65 |gn of..t|he syste|
|00000430| 6d 2e 20 59 6f 75 20 6d | 61 79 20 70 72 65 66 65 |m. You m|ay prefe|
|00000440| 72 20 74 6f 20 73 6b 69 | 70 20 74 68 69 73 20 63 |r to ski|p this c|
|00000450| 68 61 70 74 65 72 20 74 | 68 65 20 66 69 72 73 74 |hapter t|he first|
|00000460| 20 74 69 6d 65 20 79 6f | 75 20 72 65 61 64 0d 0a | time yo|u read..|
|00000470| 74 68 69 73 20 41 75 74 | 68 6f 72 27 73 20 4d 61 |this Aut|hor's Ma|
|00000480| 6e 75 61 6c 2c 20 61 6e | 64 20 63 6f 6d 65 20 62 |nual, an|d come b|
|00000490| 61 63 6b 20 74 6f 20 69 | 74 20 61 66 74 65 72 20 |ack to i|t after |
|000004a0| 79 6f 75 20 68 61 76 65 | 20 61 20 67 65 6e 65 72 |you have| a gener|
|000004b0| 61 6c 0d 0a 75 6e 64 65 | 72 73 74 61 6e 64 69 6e |al..unde|rstandin|
|000004c0| 67 20 6f 66 20 74 68 65 | 20 6c 61 6e 67 75 61 67 |g of the| languag|
|000004d0| 65 2e 5c 62 75 6c 6c 0d | 0a 0d 0a 5c 63 68 61 70 |e.\bull.|...\chap|
|000004e0| 74 65 72 62 6f 64 79 0d | 0a 0d 0a 5c 6d 61 6a 6f |terbody.|...\majo|
|000004f0| 72 73 65 63 74 69 6f 6e | 7b 4f 62 6a 65 63 74 2d |rsection|{Object-|
|00000500| 4f 72 69 65 6e 74 65 64 | 20 50 72 6f 67 72 61 6d |Oriented| Program|
|00000510| 6d 69 6e 67 7d 0d 0a 0d | 0a 54 41 44 53 20 69 73 |ming}...|.TADS is|
|00000520| 20 61 6e 20 7b 5c 73 6c | 20 5e 7b 6f 62 6a 65 63 | an {\sl| ^{objec|
|00000530| 74 2d 6f 72 69 65 6e 74 | 65 64 7d 7d 20 70 72 6f |t-orient|ed}} pro|
|00000540| 67 72 61 6d 6d 69 6e 67 | 20 6c 61 6e 67 75 61 67 |gramming| languag|
|00000550| 65 2e 0d 0a 4f 62 6a 65 | 63 74 2d 6f 72 69 65 6e |e...Obje|ct-orien|
|00000560| 74 65 64 20 6c 61 6e 67 | 75 61 67 65 73 20 61 72 |ted lang|uages ar|
|00000570| 65 20 73 69 6d 69 6c 61 | 72 20 69 6e 20 6d 61 6e |e simila|r in man|
|00000580| 79 20 77 61 79 73 20 74 | 6f 20 60 60 70 72 6f 63 |y ways t|o ``proc|
|00000590| 65 64 75 72 61 6c 22 0d | 0a 6c 61 6e 67 75 61 67 |edural".|.languag|
|000005a0| 65 73 20 73 75 63 68 20 | 61 73 20 5e 7b 43 7d 20 |es such |as ^{C} |
|000005b0| 61 6e 64 20 5e 7b 50 61 | 73 63 61 6c 7d 2c 20 62 |and ^{Pa|scal}, b|
|000005c0| 75 74 20 61 70 70 72 6f | 61 63 68 20 70 72 6f 62 |ut appro|ach prob|
|000005d0| 6c 65 6d 2d 73 6f 6c 76 | 69 6e 67 0d 0a 66 72 6f |lem-solv|ing..fro|
|000005e0| 6d 20 61 20 64 69 66 66 | 65 72 65 6e 74 20 70 65 |m a diff|erent pe|
|000005f0| 72 73 70 65 63 74 69 76 | 65 2e 20 20 42 65 63 61 |rspectiv|e. Beca|
|00000600| 75 73 65 20 6f 66 20 74 | 68 65 20 73 68 69 66 74 |use of t|he shift|
|00000610| 20 69 6e 20 76 69 65 77 | 70 6f 69 6e 74 2c 0d 0a | in view|point,..|
|00000620| 6f 62 6a 65 63 74 2d 6f | 72 69 65 6e 74 65 64 20 |object-o|riented |
|00000630| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 69 73 20 65 |programm|ing is e|
|00000640| 66 66 65 63 74 69 76 65 | 20 69 6e 20 6d 61 6e 79 |ffective| in many|
|00000650| 20 64 69 66 66 65 72 65 | 6e 74 20 6b 69 6e 64 73 | differe|nt kinds|
|00000660| 20 6f 66 0d 0a 61 70 70 | 6c 69 63 61 74 69 6f 6e | of..app|lication|
|00000670| 73 2c 20 62 75 74 20 69 | 74 20 69 73 20 70 61 72 |s, but i|t is par|
|00000680| 74 69 63 75 6c 61 72 6c | 79 20 61 70 70 6c 69 63 |ticularl|y applic|
|00000690| 61 62 6c 65 20 74 6f 20 | 73 69 6d 75 6c 61 74 69 |able to |simulati|
|000006a0| 6f 6e 73 2e 0d 0a 41 20 | 74 65 78 74 20 61 64 76 |ons...A |text adv|
|000006b0| 65 6e 74 75 72 65 20 69 | 73 20 66 75 6e 64 61 6d |enture i|s fundam|
|000006c0| 65 6e 74 61 6c 6c 79 20 | 61 20 73 69 6d 75 6c 61 |entally |a simula|
|000006d0| 74 69 6f 6e 2e 0d 0a 0d | 0a 57 68 61 74 20 69 73 |tion....|.What is|
|000006e0| 20 74 68 69 73 20 60 60 | 6e 65 77 20 70 65 72 73 | this ``|new pers|
|000006f0| 70 65 63 74 69 76 65 22 | 20 6f 66 20 6f 62 6a 65 |pective"| of obje|
|00000700| 63 74 2d 6f 72 69 65 6e | 74 65 64 20 70 72 6f 67 |ct-orien|ted prog|
|00000710| 72 61 6d 6d 69 6e 67 3f | 20 42 61 73 69 63 61 6c |ramming?| Basical|
|00000720| 6c 79 2c 0d 0a 69 74 20 | 69 73 20 74 68 65 20 76 |ly,..it |is the v|
|00000730| 69 65 77 20 74 68 61 74 | 20 6f 6e 65 20 74 61 6b |iew that| one tak|
|00000740| 65 73 20 6f 66 20 64 61 | 74 61 2e 20 20 49 6e 20 |es of da|ta. In |
|00000750| 61 20 74 72 61 64 69 74 | 69 6f 6e 61 6c 20 6c 61 |a tradit|ional la|
|00000760| 6e 67 75 61 67 65 2c 20 | 79 6f 75 0d 0a 77 72 69 |nguage, |you..wri|
|00000770| 74 65 20 61 20 73 65 72 | 69 65 73 20 6f 66 20 70 |te a ser|ies of p|
|00000780| 72 6f 63 65 64 75 72 61 | 6c 20 73 74 65 70 73 20 |rocedura|l steps |
|00000790| 74 68 61 74 20 61 72 65 | 20 61 70 70 6c 69 65 64 |that are| applied|
|000007a0| 20 74 6f 20 61 20 63 6f | 6c 6c 65 63 74 69 6f 6e | to a co|llection|
|000007b0| 20 6f 66 20 64 61 74 61 | 3b 0d 0a 63 6f 64 65 20 | of data|;..code |
|000007c0| 61 6e 64 20 64 61 74 61 | 20 61 72 65 20 66 69 72 |and data| are fir|
|000007d0| 6d 6c 79 20 73 65 70 61 | 72 61 74 65 64 2e 20 20 |mly sepa|rated. |
|000007e0| 49 6e 20 6f 62 6a 65 63 | 74 2d 6f 72 69 65 6e 74 |In objec|t-orient|
|000007f0| 65 64 20 70 72 6f 67 72 | 61 6d 6d 69 6e 67 2c 0d |ed progr|amming,.|
|00000800| 0a 6f 6e 20 74 68 65 20 | 6f 74 68 65 72 20 68 61 |.on the |other ha|
|00000810| 6e 64 2c 0d 0a 79 6f 75 | 20 70 61 72 74 69 74 69 |nd,..you| partiti|
|00000820| 6f 6e 20 61 20 70 72 6f | 62 6c 65 6d 20 69 6e 74 |on a pro|blem int|
|00000830| 6f 20 61 20 73 65 74 20 | 6f 66 20 65 6e 74 69 74 |o a set |of entit|
|00000840| 69 65 73 2c 20 63 61 6c | 6c 65 64 20 7b 5c 73 6c |ies, cal|led {\sl|
|00000850| 20 5e 7b 6f 62 6a 65 63 | 74 7d 73 7d 3b 0d 0a 65 | ^{objec|t}s};..e|
|00000860| 61 63 68 20 6f 62 6a 65 | 63 74 20 63 6f 6e 74 61 |ach obje|ct conta|
|00000870| 69 6e 73 20 62 6f 74 68 | 20 74 68 65 0d 0a 64 61 |ins both| the..da|
|00000880| 74 61 20 61 6e 64 20 74 | 68 65 20 63 6f 64 65 20 |ta and t|he code |
|00000890| 74 68 61 74 20 64 65 73 | 63 72 69 62 65 73 20 69 |that des|cribes i|
|000008a0| 74 73 20 73 74 61 74 65 | 20 61 6e 64 20 62 65 68 |ts state| and beh|
|000008b0| 61 76 69 6f 72 2e 0d 0a | 49 6e 20 61 20 73 69 6d |avior...|In a sim|
|000008c0| 75 6c 61 74 69 6f 6e 2c | 20 61 6e 20 6f 62 6a 65 |ulation,| an obje|
|000008d0| 63 74 20 69 6e 20 74 68 | 65 20 70 72 6f 67 72 61 |ct in th|e progra|
|000008e0| 6d 20 75 73 75 61 6c 6c | 79 20 63 6f 72 72 65 73 |m usuall|y corres|
|000008f0| 70 6f 6e 64 73 20 64 69 | 72 65 63 74 6c 79 20 74 |ponds di|rectly t|
|00000900| 6f 0d 0a 61 6e 20 6f 62 | 6a 65 63 74 20 62 65 69 |o..an ob|ject bei|
|00000910| 6e 67 20 6d 6f 64 65 6c | 6c 65 64 2e 0d 0a 0d 0a |ng model|led.....|
|00000920| 5c 6d 69 6e 6f 72 73 65 | 63 74 69 6f 6e 7b 42 6f |\minorse|ction{Bo|
|00000930| 75 6e 63 69 6e 67 20 42 | 61 6c 6c 73 7d 0d 0a 0d |uncing B|alls}...|
|00000940| 0a 43 6f 6e 73 69 64 65 | 72 20 61 20 73 69 6d 75 |.Conside|r a simu|
|00000950| 6c 61 74 69 6f 6e 20 6f | 66 20 61 20 70 68 79 73 |lation o|f a phys|
|00000960| 69 63 73 20 70 72 6f 62 | 6c 65 6d 20 69 6e 76 6f |ics prob|lem invo|
|00000970| 6c 76 69 6e 67 20 62 6f | 75 6e 63 69 6e 67 20 62 |lving bo|uncing b|
|00000980| 61 6c 6c 73 20 6f 66 0d | 0a 76 61 72 69 6f 75 73 |alls of.|.various|
|00000990| 20 6b 69 6e 64 73 2e 20 | 20 49 6e 20 61 20 74 72 | kinds. | In a tr|
|000009a0| 61 64 69 74 69 6f 6e 61 | 6c 20 6c 61 6e 67 75 61 |aditiona|l langua|
|000009b0| 67 65 2c 20 77 65 20 77 | 6f 75 6c 64 20 64 65 66 |ge, we w|ould def|
|000009c0| 69 6e 65 20 61 20 73 65 | 74 20 6f 66 20 64 61 74 |ine a se|t of dat|
|000009d0| 61 0d 0a 66 6f 72 20 65 | 61 63 68 20 62 61 6c 6c |a..for e|ach ball|
|000009e0| 20 28 73 75 63 68 20 61 | 73 20 69 74 73 20 70 6f | (such a|s its po|
|000009f0| 73 69 74 69 6f 6e 2c 20 | 6d 61 73 73 2c 20 61 6e |sition, |mass, an|
|00000a00| 64 20 76 65 6c 6f 63 69 | 74 79 29 3b 20 77 65 20 |d veloci|ty); we |
|00000a10| 77 6f 75 6c 64 20 67 69 | 76 65 0d 0a 65 61 63 68 |would gi|ve..each|
|00000a20| 20 62 61 6c 6c 20 73 6f | 6d 65 20 73 6f 72 74 20 | ball so|me sort |
|00000a30| 6f 66 20 69 64 65 6e 74 | 69 66 69 63 61 74 69 6f |of ident|ificatio|
|00000a40| 6e 20 28 70 65 72 68 61 | 70 73 20 61 20 6e 75 6d |n (perha|ps a num|
|00000a50| 62 65 72 2c 20 67 69 76 | 69 6e 67 20 61 6e 20 61 |ber, giv|ing an a|
|00000a60| 72 72 61 79 0d 0a 69 6e | 64 65 78 29 20 74 68 61 |rray..in|dex) tha|
|00000a70| 74 20 77 6f 75 6c 64 20 | 6c 65 74 20 75 73 20 74 |t would |let us t|
|00000a80| 65 6c 6c 20 74 68 65 20 | 62 61 6c 6c 73 20 61 70 |ell the |balls ap|
|00000a90| 61 72 74 2e 20 20 46 69 | 6e 61 6c 6c 79 2c 20 61 |art. Fi|nally, a|
|00000aa0| 20 73 75 62 72 6f 75 74 | 69 6e 65 0d 0a 6e 61 6d | subrout|ine..nam|
|00000ab0| 65 64 20 7b 5c 74 74 20 | 62 6f 75 6e 63 65 7d 20 |ed {\tt |bounce} |
|00000ac0| 77 6f 75 6c 64 20 62 65 | 20 77 72 69 74 74 65 6e |would be| written|
|00000ad0| 3b 20 74 68 65 20 73 75 | 62 72 6f 75 74 69 6e 65 |; the su|broutine|
|00000ae0| 20 77 6f 75 6c 64 20 74 | 61 6b 65 20 61 20 62 61 | would t|ake a ba|
|00000af0| 6c 6c 0d 0a 6e 75 6d 62 | 65 72 20 61 73 20 69 74 |ll..numb|er as it|
|00000b00| 73 20 70 61 72 61 6d 65 | 74 65 72 2c 20 61 6e 64 |s parame|ter, and|
|00000b10| 20 77 6f 75 6c 64 20 61 | 70 70 6c 79 20 74 68 65 | would a|pply the|
|00000b20| 20 61 70 70 72 6f 70 72 | 69 61 74 65 20 63 68 61 | appropr|iate cha|
|00000b30| 6e 67 65 73 20 74 6f 20 | 74 68 65 0d 0a 62 61 6c |nges to |the..bal|
|00000b40| 6c 27 73 20 64 61 74 61 | 2e 0d 0a 0d 0a 49 6e 20 |l's data|.....In |
|00000b50| 63 6f 6e 74 72 61 73 74 | 2c 20 61 6e 20 6f 62 6a |contrast|, an obj|
|00000b60| 65 63 74 2d 6f 72 69 65 | 6e 74 65 64 20 76 65 72 |ect-orie|nted ver|
|00000b70| 73 69 6f 6e 20 6f 66 20 | 74 68 65 20 70 72 6f 67 |sion of |the prog|
|00000b80| 72 61 6d 20 77 6f 75 6c | 64 20 6d 6f 64 65 6c 20 |ram woul|d model |
|00000b90| 65 61 63 68 0d 0a 62 61 | 6c 6c 20 77 69 74 68 20 |each..ba|ll with |
|00000ba0| 61 6e 20 6f 62 6a 65 63 | 74 2e 20 20 4e 6f 74 20 |an objec|t. Not |
|00000bb0| 6f 6e 6c 79 20 77 6f 75 | 6c 64 20 74 68 65 20 64 |only wou|ld the d|
|00000bc0| 61 74 61 20 61 62 6f 75 | 74 20 61 0d 0a 62 61 6c |ata abou|t a..bal|
|00000bd0| 6c 20 62 65 20 63 6f 6e | 74 61 69 6e 65 64 20 69 |l be con|tained i|
|00000be0| 6e 20 74 68 65 20 6f 62 | 6a 65 63 74 20 72 65 70 |n the ob|ject rep|
|00000bf0| 72 65 73 65 6e 74 69 6e | 67 20 74 68 65 20 62 61 |resentin|g the ba|
|00000c00| 6c 6c 2c 20 62 75 74 20 | 74 68 65 20 63 6f 64 65 |ll, but |the code|
|00000c10| 20 6e 65 65 64 65 64 20 | 74 6f 0d 0a 64 65 73 63 | needed |to..desc|
|00000c20| 72 69 62 65 20 69 74 73 | 20 62 65 68 61 76 69 6f |ribe its| behavio|
|00000c30| 72 20 75 6e 64 65 72 20 | 76 61 72 69 6f 75 73 20 |r under |various |
|00000c40| 69 6e 74 65 72 61 63 74 | 69 6f 6e 73 20 77 6f 75 |interact|ions wou|
|00000c50| 6c 64 20 62 65 20 63 6f | 6e 74 61 69 6e 65 64 20 |ld be co|ntained |
|00000c60| 69 6e 20 74 68 65 0d 0a | 6f 62 6a 65 63 74 20 61 |in the..|object a|
|00000c70| 73 20 77 65 6c 6c 2e 20 | 20 53 6f 2c 20 65 61 63 |s well. | So, eac|
|00000c80| 68 20 62 61 6c 6c 20 77 | 6f 75 6c 64 20 68 61 76 |h ball w|ould hav|
|00000c90| 65 20 69 74 73 20 6f 77 | 6e 0d 0a 7b 5c 74 74 20 |e its ow|n..{\tt |
|00000ca0| 62 6f 75 6e 63 65 7d 20 | 7b 5c 73 6c 20 5e 7b 6d |bounce} |{\sl ^{m|
|00000cb0| 65 74 68 6f 64 7d 7d 20 | 28 74 68 65 20 6f 62 6a |ethod}} |(the obj|
|00000cc0| 65 63 74 2d 6f 72 69 65 | 6e 74 65 64 20 77 6f 72 |ect-orie|nted wor|
|00000cd0| 64 20 66 6f 72 20 61 20 | 73 75 62 72 6f 75 74 69 |d for a |subrouti|
|00000ce0| 6e 65 0d 0a 74 68 61 74 | 20 69 73 20 61 73 73 6f |ne..that| is asso|
|00000cf0| 63 69 61 74 65 64 20 77 | 69 74 68 20 61 20 70 61 |ciated w|ith a pa|
|00000d00| 72 74 69 63 75 6c 61 72 | 20 6f 62 6a 65 63 74 20 |rticular| object |
|00000d10| 6f 72 20 67 72 6f 75 70 | 20 6f 66 20 6f 62 6a 65 |or group| of obje|
|00000d20| 63 74 73 29 2e 20 20 52 | 61 74 68 65 72 20 74 68 |cts). R|ather th|
|00000d30| 61 6e 0d 0a 63 61 6c 6c | 69 6e 67 20 74 68 65 20 |an..call|ing the |
|00000d40| 7b 5c 74 74 20 62 6f 75 | 6e 63 65 7d 20 73 75 62 |{\tt bou|nce} sub|
|00000d50| 72 6f 75 74 69 6e 65 20 | 77 69 74 68 20 61 6e 20 |routine |with an |
|00000d60| 61 72 67 75 6d 65 6e 74 | 20 73 70 65 63 69 66 79 |argument| specify|
|00000d70| 69 6e 67 20 62 61 6c 6c | 20 33 2c 0d 0a 79 6f 75 |ing ball| 3,..you|
|00000d80| 20 77 6f 75 6c 64 20 73 | 65 6e 64 20 62 61 6c 6c | would s|end ball|
|00000d90| 20 33 20 61 20 0d 0a 7b | 5c 73 6c 20 6d 65 73 73 | 3 a ..{|\sl mess|
|00000da0| 61 67 65 7d 20 74 65 6c | 6c 69 6e 67 20 69 74 20 |age} tel|ling it |
|00000db0| 74 6f 20 62 6f 75 6e 63 | 65 20 28 60 60 73 65 6e |to bounc|e (``sen|
|00000dc0| 64 20 61 20 6d 65 73 73 | 61 67 65 22 20 69 73 20 |d a mess|age" is |
|00000dd0| 74 68 65 20 6f 62 6a 65 | 63 74 2d 6f 72 69 65 6e |the obje|ct-orien|
|00000de0| 74 65 64 0d 0a 74 65 72 | 6d 20 66 6f 72 20 63 61 |ted..ter|m for ca|
|00000df0| 6c 6c 69 6e 67 20 61 20 | 6d 65 74 68 6f 64 29 2e |lling a |method).|
|00000e00| 0d 0a 0d 0a 5c 6d 69 6e | 6f 72 73 65 63 74 69 6f |....\min|orsectio|
|00000e10| 6e 7b 49 6e 68 65 72 69 | 74 61 6e 63 65 20 61 6e |n{Inheri|tance an|
|00000e20| 64 20 4f 76 65 72 72 69 | 64 69 6e 67 7d 0d 0a 0d |d Overri|ding}...|
|00000e30| 0a 54 68 69 73 20 6d 61 | 79 20 73 6f 75 6e 64 20 |.This ma|y sound |
|00000e40| 6c 69 6b 65 20 61 20 6c | 6f 74 20 6f 66 20 63 6f |like a l|ot of co|
|00000e50| 64 69 6e 67 2c 20 77 72 | 69 74 69 6e 67 20 74 68 |ding, wr|iting th|
|00000e60| 65 20 73 61 6d 65 20 73 | 75 62 72 6f 75 74 69 6e |e same s|ubroutin|
|00000e70| 65 20 66 6f 72 20 65 61 | 63 68 20 62 61 6c 6c 2e |e for ea|ch ball.|
|00000e80| 0d 0a 46 6f 72 74 75 6e | 61 74 65 6c 79 2c 20 6f |..Fortun|ately, o|
|00000e90| 62 6a 65 63 74 2d 6f 72 | 69 65 6e 74 65 64 20 6c |bject-or|iented l|
|00000ea0| 61 6e 67 75 61 67 65 73 | 20 68 61 76 65 20 61 20 |anguages| have a |
|00000eb0| 66 65 61 74 75 72 65 20 | 74 68 61 74 20 61 76 6f |feature |that avo|
|00000ec0| 69 64 73 20 74 68 69 73 | 20 74 79 70 65 20 6f 66 |ids this| type of|
|00000ed0| 0d 0a 64 75 70 6c 69 63 | 61 74 69 6f 6e 2e 20 20 |..duplic|ation. |
|00000ee0| 54 68 69 73 20 66 65 61 | 74 75 72 65 20 69 73 20 |This fea|ture is |
|00000ef0| 7b 5c 73 6c 20 5e 7b 69 | 6e 68 65 72 69 74 61 6e |{\sl ^{i|nheritan|
|00000f00| 63 65 7d 7d 2e 20 20 41 | 6e 20 6f 62 6a 65 63 74 |ce}}. A|n object|
|00000f10| 20 63 61 6e 20 62 65 0d | 0a 64 65 66 69 6e 65 64 | can be.|.defined|
|00000f20| 20 61 73 20 62 65 6c 6f | 6e 67 69 6e 67 20 74 6f | as belo|nging to|
|00000f30| 20 61 20 70 61 72 74 69 | 63 75 6c 61 72 20 7b 5c | a parti|cular {\|
|00000f40| 73 6c 20 5e 7b 63 6c 61 | 73 73 7d 7d 2c 20 61 6e |sl ^{cla|ss}}, an|
|00000f50| 64 20 69 74 20 77 69 6c | 6c 20 69 6e 68 65 72 69 |d it wil|l inheri|
|00000f60| 74 20 61 6c 6c 20 6f 66 | 0d 0a 74 68 65 20 63 6f |t all of|..the co|
|00000f70| 64 65 20 61 6e 64 20 64 | 61 74 61 20 64 65 66 69 |de and d|ata defi|
|00000f80| 6e 65 64 20 66 6f 72 20 | 74 68 65 20 63 6c 61 73 |ned for |the clas|
|00000f90| 73 2e 20 20 4f 66 20 63 | 6f 75 72 73 65 2c 20 69 |s. Of c|ourse, i|
|00000fa0| 74 20 63 61 6e 20 73 74 | 69 6c 6c 20 64 65 66 69 |t can st|ill defi|
|00000fb0| 6e 65 20 63 6f 64 65 0d | 0a 61 6e 64 20 64 61 74 |ne code.|.and dat|
|00000fc0| 61 20 69 74 73 65 6c 66 | 2c 20 77 68 69 63 68 20 |a itself|, which |
|00000fd0| 63 61 6e 20 61 64 64 20 | 74 6f 20 6f 72 20 6d 6f |can add |to or mo|
|00000fe0| 64 69 66 79 20 74 68 65 | 20 61 74 74 72 69 62 75 |dify the| attribu|
|00000ff0| 74 65 73 20 69 74 20 69 | 6e 68 65 72 69 74 73 2e |tes it i|nherits.|
|00001000| 0d 0a 57 68 65 6e 20 61 | 6e 20 6f 62 6a 65 63 74 |..When a|n object|
|00001010| 20 64 65 66 69 6e 65 73 | 20 63 6f 64 65 20 6f 72 | defines| code or|
|00001020| 20 64 61 74 61 20 74 68 | 61 74 20 69 73 20 61 6c | data th|at is al|
|00001030| 72 65 61 64 79 20 64 65 | 66 69 6e 65 64 20 62 79 |ready de|fined by|
|00001040| 0d 0a 69 74 73 20 63 6c | 61 73 73 2c 20 74 68 65 |..its cl|ass, the|
|00001050| 20 64 65 66 69 6e 69 74 | 69 6f 6e 73 20 74 68 65 | definit|ions the|
|00001060| 20 6f 62 6a 65 63 74 20 | 6d 61 6b 65 73 20 7b 5c | object |makes {\|
|00001070| 73 6c 20 5e 7b 6f 76 65 | 72 72 69 64 65 7d 7d 0d |sl ^{ove|rride}}.|
|00001080| 0a 77 68 61 74 20 69 74 | 20 69 6e 68 65 72 69 74 |.what it| inherit|
|00001090| 73 20 66 72 6f 6d 20 69 | 74 73 20 63 6c 61 73 73 |s from i|ts class|
|000010a0| 2e 0d 0a 0d 0a 54 68 65 | 20 75 74 69 6c 69 74 79 |.....The| utility|
|000010b0| 20 6f 66 20 69 6e 68 65 | 72 69 74 61 6e 63 65 20 | of inhe|ritance |
|000010c0| 61 6e 64 20 6f 76 65 72 | 72 69 64 69 6e 67 20 69 |and over|riding i|
|000010d0| 73 20 74 68 61 74 20 69 | 74 20 62 65 63 6f 6d 65 |s that i|t become|
|000010e0| 73 20 76 65 72 79 0d 0a | 73 69 6d 70 6c 65 20 74 |s very..|simple t|
|000010f0| 6f 20 72 65 70 72 65 73 | 65 6e 74 20 67 65 6e 65 |o repres|ent gene|
|00001100| 72 61 6c 20 61 6e 64 20 | 73 70 65 63 69 61 6c 20 |ral and |special |
|00001110| 63 61 73 65 73 2e 20 20 | 46 6f 72 20 65 78 61 6d |cases. |For exam|
|00001120| 70 6c 65 2c 20 69 66 20 | 79 6f 75 20 68 61 64 0d |ple, if |you had.|
|00001130| 0a 74 77 65 6e 74 79 20 | 69 64 65 6e 74 69 63 61 |.twenty |identica|
|00001140| 6c 20 62 61 6c 6c 73 2c | 20 62 75 74 20 61 20 74 |l balls,| but a t|
|00001150| 77 65 6e 74 79 2d 66 69 | 72 73 74 20 62 61 6c 6c |wenty-fi|rst ball|
|00001160| 20 77 69 74 68 20 73 70 | 65 63 69 61 6c 0d 0a 62 | with sp|ecial..b|
|00001170| 65 68 61 76 69 6f 72 20 | 77 68 65 6e 20 62 6f 75 |ehavior |when bou|
|00001180| 6e 63 69 6e 67 20 28 62 | 75 74 20 61 70 61 72 74 |ncing (b|ut apart|
|00001190| 20 66 72 6f 6d 20 62 6f | 75 6e 63 69 6e 67 20 69 | from bo|uncing i|
|000011a0| 73 20 74 68 65 20 73 61 | 6d 65 20 61 73 20 61 6c |s the sa|me as al|
|000011b0| 6c 20 74 68 65 20 6f 74 | 68 65 72 0d 0a 62 61 6c |l the ot|her..bal|
|000011c0| 6c 73 29 2c 20 79 6f 75 | 27 64 20 66 69 72 73 74 |ls), you|'d first|
|000011d0| 20 64 65 66 69 6e 65 20 | 61 20 7b 5c 74 74 20 62 | define |a {\tt b|
|000011e0| 61 6c 6c 7d 20 63 6c 61 | 73 73 2c 20 61 6e 64 20 |all} cla|ss, and |
|000011f0| 64 65 66 69 6e 65 20 61 | 6c 6c 20 74 77 65 6e 74 |define a|ll twent|
|00001200| 79 2d 6f 6e 65 20 62 61 | 6c 6c 73 0d 0a 61 73 20 |y-one ba|lls..as |
|00001210| 62 65 6c 6f 6e 67 69 6e | 67 20 74 6f 20 74 68 69 |belongin|g to thi|
|00001220| 73 20 63 6c 61 73 73 2e | 20 20 54 68 65 20 74 77 |s class.| The tw|
|00001230| 65 6e 74 79 2d 66 69 72 | 73 74 20 62 61 6c 6c 2c |enty-fir|st ball,|
|00001240| 20 74 68 6f 75 67 68 2c | 20 77 6f 75 6c 64 20 6f | though,| would o|
|00001250| 76 65 72 72 69 64 65 0d | 0a 74 68 65 20 7b 5c 74 |verride.|.the {\t|
|00001260| 74 20 62 6f 75 6e 63 65 | 7d 20 6d 65 74 68 6f 64 |t bounce|} method|
|00001270| 20 77 69 74 68 20 69 74 | 73 20 6f 77 6e 0d 0a 73 | with it|s own..s|
|00001280| 70 65 63 69 61 6c 20 76 | 65 72 73 69 6f 6e 2e 20 |pecial v|ersion. |
|00001290| 20 49 6e 20 61 20 74 72 | 61 64 69 74 69 6f 6e 61 | In a tr|aditiona|
|000012a0| 6c 20 6c 61 6e 67 75 61 | 67 65 2c 20 6f 6e 20 74 |l langua|ge, on t|
|000012b0| 68 65 20 6f 74 68 65 72 | 20 68 61 6e 64 2c 20 74 |he other| hand, t|
|000012c0| 68 65 0d 0a 7b 5c 74 74 | 20 62 6f 75 6e 63 65 7d |he..{\tt| bounce}|
|000012d0| 20 73 75 62 72 6f 75 74 | 69 6e 65 20 77 6f 75 6c | subrout|ine woul|
|000012e0| 64 20 6e 65 65 64 20 61 | 20 73 70 65 63 69 61 6c |d need a| special|
|000012f0| 20 74 65 73 74 20 74 6f | 20 73 65 65 20 69 66 20 | test to| see if |
|00001300| 74 68 65 20 6f 64 64 0d | 0a 62 61 6c 6c 20 77 61 |the odd.|.ball wa|
|00001310| 73 20 62 6f 75 6e 63 69 | 6e 67 20 61 6e 64 20 61 |s bounci|ng and a|
|00001320| 63 74 20 61 63 63 6f 72 | 64 69 6e 67 6c 79 2e 0d |ct accor|dingly..|
|00001330| 0a 0d 0a 54 68 69 73 20 | 6d 61 79 20 73 65 65 6d |...This |may seem|
|00001340| 20 6c 69 6b 65 20 73 69 | 78 20 6f 66 20 6f 6e 65 | like si|x of one|
|00001350| 20 61 6e 64 20 68 61 6c | 66 20 61 20 64 6f 7a 65 | and hal|f a doze|
|00001360| 6e 20 6f 66 20 74 68 65 | 20 6f 74 68 65 72 2c 20 |n of the| other, |
|00001370| 62 75 74 20 69 74 20 68 | 61 73 20 61 0d 0a 62 69 |but it h|as a..bi|
|00001380| 67 20 61 64 76 61 6e 74 | 61 67 65 3a 20 20 69 74 |g advant|age: it|
|00001390| 20 69 73 6f 6c 61 74 65 | 73 20 74 68 65 20 73 70 | isolate|s the sp|
|000013a0| 65 63 69 61 6c 20 63 61 | 73 65 20 63 6f 64 65 20 |ecial ca|se code |
|000013b0| 77 69 74 68 20 74 68 65 | 20 73 70 65 63 69 61 6c |with the| special|
|000013c0| 20 63 61 73 65 0d 0a 6f | 62 6a 65 63 74 2e 20 20 | case..o|bject. |
|000013d0| 4a 75 73 74 20 61 73 20 | 62 6c 6f 63 6b 2d 73 74 |Just as |block-st|
|000013e0| 72 75 63 74 75 72 65 64 | 20 6c 61 6e 67 75 61 67 |ructured| languag|
|000013f0| 65 73 20 61 6c 6c 6f 77 | 20 63 6f 64 65 20 74 6f |es allow| code to|
|00001400| 20 62 65 20 6d 6f 64 75 | 6c 61 72 69 7a 65 64 2c | be modu|larized,|
|00001410| 0d 0a 6f 62 6a 65 63 74 | 2d 6f 72 69 65 6e 74 65 |..object|-oriente|
|00001420| 64 20 6c 61 6e 67 75 61 | 67 65 73 20 61 6c 6c 6f |d langua|ges allo|
|00001430| 77 20 65 6e 74 69 72 65 | 20 6f 62 6a 65 63 74 73 |w entire| objects|
|00001440| 2d 2d 2d 62 6f 74 68 20 | 74 68 65 69 72 20 73 74 |---both |their st|
|00001450| 61 74 65 20 7b 5c 69 74 | 20 61 6e 64 7d 0d 0a 74 |ate {\it| and}..t|
|00001460| 68 65 69 72 20 62 65 68 | 61 76 69 6f 72 2d 2d 2d |heir beh|avior---|
|00001470| 74 6f 20 62 65 20 6d 6f | 64 75 6c 61 72 69 7a 65 |to be mo|dularize|
|00001480| 64 2e 20 20 4d 6f 73 74 | 20 70 65 6f 70 6c 65 20 |d. Most| people |
|00001490| 66 69 6e 64 20 74 68 61 | 74 20 74 68 69 73 20 6d |find tha|t this m|
|000014a0| 61 6b 65 73 20 77 72 69 | 74 69 6e 67 0d 0a 61 20 |akes wri|ting..a |
|000014b0| 70 72 6f 67 72 61 6d 20 | 6d 75 63 68 20 65 61 73 |program |much eas|
|000014c0| 69 65 72 2c 20 62 65 63 | 61 75 73 65 20 74 68 65 |ier, bec|ause the|
|000014d0| 79 20 6f 6e 6c 79 20 6e | 65 65 64 20 74 6f 20 74 |y only n|eed to t|
|000014e0| 68 69 6e 6b 20 61 62 6f | 75 74 20 61 0d 0a 73 70 |hink abo|ut a..sp|
|000014f0| 65 63 69 61 6c 20 63 61 | 73 65 20 69 6e 20 6f 6e |ecial ca|se in on|
|00001500| 65 20 70 6c 61 63 65 2c | 20 72 61 74 68 65 72 20 |e place,| rather |
|00001510| 74 68 61 6e 20 74 72 61 | 63 6b 69 6e 67 20 64 6f |than tra|cking do|
|00001520| 77 6e 20 61 6c 6c 20 74 | 68 65 20 73 75 62 72 6f |wn all t|he subro|
|00001530| 75 74 69 6e 65 73 0d 0a | 74 68 61 74 20 6e 65 65 |utines..|that nee|
|00001540| 64 20 74 6f 20 62 65 20 | 6d 6f 64 69 66 69 65 64 |d to be |modified|
|00001550| 2e 20 20 49 74 20 69 73 | 20 65 73 70 65 63 69 61 |. It is| especia|
|00001560| 6c 6c 79 20 68 65 6c 70 | 66 75 6c 20 77 68 65 6e |lly help|ful when|
|00001570| 20 64 65 62 75 67 67 69 | 6e 67 20 61 6e 64 0d 0a | debuggi|ng and..|
|00001580| 6d 61 69 6e 74 61 69 6e | 69 6e 67 20 61 20 70 72 |maintain|ing a pr|
|00001590| 6f 67 72 61 6d 2c 20 62 | 65 63 61 75 73 65 20 65 |ogram, b|ecause e|
|000015a0| 76 65 72 79 74 68 69 6e | 67 20 70 65 72 74 61 69 |verythin|g pertai|
|000015b0| 6e 69 6e 67 20 74 6f 20 | 61 6e 20 6f 62 6a 65 63 |ning to |an objec|
|000015c0| 74 20 69 73 20 6b 65 70 | 74 0d 0a 69 6e 20 6f 6e |t is kep|t..in on|
|000015d0| 65 20 70 6c 61 63 65 2e | 0d 0a 0d 0a 4e 6f 74 65 |e place.|....Note|
|000015e0| 20 74 68 61 74 20 73 69 | 6e 63 65 20 61 20 63 6c | that si|nce a cl|
|000015f0| 61 73 73 20 63 61 6e 20 | 69 74 73 65 6c 66 20 62 |ass can |itself b|
|00001600| 65 20 61 20 6d 65 6d 62 | 65 72 20 6f 66 20 61 6e |e a memb|er of an|
|00001610| 6f 74 68 65 72 20 63 6c | 61 73 73 2c 20 74 68 69 |other cl|ass, thi|
|00001620| 73 20 74 79 70 65 20 6f | 66 0d 0a 73 70 65 63 69 |s type o|f..speci|
|00001630| 61 6c 69 7a 61 74 69 6f | 6e 20 63 61 6e 20 62 65 |alizatio|n can be|
|00001640| 20 65 78 74 65 6e 64 65 | 64 20 69 6e 64 65 66 69 | extende|d indefi|
|00001650| 6e 69 74 65 6c 79 2e 20 | 20 46 6f 72 20 65 78 61 |nitely. | For exa|
|00001660| 6d 70 6c 65 2c 20 79 6f | 75 20 63 6f 75 6c 64 20 |mple, yo|u could |
|00001670| 64 65 66 69 6e 65 0d 0a | 74 68 65 20 63 6c 61 73 |define..|the clas|
|00001680| 73 65 73 20 7b 5c 74 74 | 20 72 75 62 62 65 72 42 |ses {\tt| rubberB|
|00001690| 61 6c 6c 7d 20 61 6e 64 | 20 7b 5c 74 74 20 62 69 |all} and| {\tt bi|
|000016a0| 6c 6c 69 61 72 64 42 61 | 6c 6c 7d 2c 20 65 61 63 |lliardBa|ll}, eac|
|000016b0| 68 20 69 6e 68 65 72 69 | 74 69 6e 67 0d 0a 63 68 |h inheri|ting..ch|
|000016c0| 61 72 61 63 74 65 72 69 | 73 74 69 63 73 20 66 72 |aracteri|stics fr|
|000016d0| 6f 6d 20 74 68 65 20 6d | 6f 72 65 20 67 65 6e 65 |om the m|ore gene|
|000016e0| 72 61 6c 20 63 6c 61 73 | 73 20 7b 5c 74 74 20 62 |ral clas|s {\tt b|
|000016f0| 61 6c 6c 7d 20 61 6e 64 | 20 64 65 66 69 6e 69 6e |all} and| definin|
|00001700| 67 20 73 6f 6d 65 0d 0a | 6f 66 20 74 68 65 69 72 |g some..|of their|
|00001710| 20 6f 77 6e 2e 20 20 4e | 6f 77 20 79 6f 75 20 63 | own. N|ow you c|
|00001720| 6f 75 6c 64 20 64 65 66 | 69 6e 65 20 74 65 6e 20 |ould def|ine ten |
|00001730| 6f 62 6a 65 63 74 73 20 | 6f 66 20 65 61 63 68 20 |objects |of each |
|00001740| 63 6c 61 73 73 2c 20 61 | 6e 64 20 74 68 65 73 65 |class, a|nd these|
|00001750| 0d 0a 6f 62 6a 65 63 74 | 73 20 63 6f 75 6c 64 20 |..object|s could |
|00001760| 74 68 65 6d 73 65 6c 76 | 65 73 20 64 65 66 69 6e |themselv|es defin|
|00001770| 65 20 63 68 61 72 61 63 | 74 65 72 69 73 74 69 63 |e charac|teristic|
|00001780| 73 20 6f 76 65 72 72 69 | 64 69 6e 67 20 74 68 65 |s overri|ding the|
|00001790| 69 72 20 74 77 6f 0d 0a | 70 61 72 65 6e 74 20 63 |ir two..|parent c|
|000017a0| 6c 61 73 73 65 73 2e 0d | 0a 0d 0a 5c 6d 69 6e 6f |lasses..|...\mino|
|000017b0| 72 73 65 63 74 69 6f 6e | 7b 4f 62 6a 65 63 74 2d |rsection|{Object-|
|000017c0| 4f 72 69 65 6e 74 65 64 | 20 41 64 76 65 6e 74 75 |Oriented| Adventu|
|000017d0| 72 65 73 7d 0d 0a 0d 0a | 4f 62 6a 65 63 74 2d 6f |res}....|Object-o|
|000017e0| 72 69 65 6e 74 65 64 20 | 6c 61 6e 67 75 61 67 65 |riented |language|
|000017f0| 73 20 61 72 65 20 71 75 | 69 74 65 20 75 73 65 66 |s are qu|ite usef|
|00001800| 75 6c 20 66 6f 72 20 77 | 72 69 74 69 6e 67 20 61 |ul for w|riting a|
|00001810| 64 76 65 6e 74 75 72 65 | 20 67 61 6d 65 73 2e 0d |dventure| games..|
|00001820| 0a 57 68 65 6e 20 61 20 | 70 6c 61 79 65 72 20 74 |.When a |player t|
|00001830| 79 70 65 73 20 61 20 63 | 6f 6d 6d 61 6e 64 20 69 |ypes a c|ommand i|
|00001840| 6e 20 61 20 54 41 44 53 | 20 67 61 6d 65 2c 20 74 |n a TADS| game, t|
|00001850| 68 65 20 73 79 73 74 65 | 6d 20 73 65 6e 64 73 20 |he syste|m sends |
|00001860| 63 65 72 74 61 69 6e 20 | 6d 65 73 73 61 67 65 73 |certain |messages|
|00001870| 0d 0a 74 6f 20 74 68 65 | 20 6f 62 6a 65 63 74 20 |..to the| object |
|00001880| 6f 72 20 6f 62 6a 65 63 | 74 73 20 69 6e 76 6f 6c |or objec|ts invol|
|00001890| 76 65 64 2e 20 20 49 6e | 20 74 68 69 73 20 77 61 |ved. In| this wa|
|000018a0| 79 2c 20 69 74 27 73 20 | 65 61 73 79 20 74 6f 20 |y, it's |easy to |
|000018b0| 64 65 66 69 6e 65 20 63 | 6c 61 73 73 65 73 0d 0a |define c|lasses..|
|000018c0| 6f 66 20 6f 62 6a 65 63 | 74 73 20 74 68 61 74 20 |of objec|ts that |
|000018d0| 62 65 68 61 76 65 20 69 | 6e 20 70 61 72 74 69 63 |behave i|n partic|
|000018e0| 75 6c 61 72 20 77 61 79 | 73 20 69 6e 20 72 65 73 |ular way|s in res|
|000018f0| 70 6f 6e 73 65 20 74 6f | 20 70 6c 61 79 65 72 20 |ponse to| player |
|00001900| 63 6f 6d 6d 61 6e 64 73 | 2e 0d 0a 46 6f 72 20 65 |commands|...For e|
|00001910| 78 61 6d 70 6c 65 2c 20 | 6f 62 6a 65 63 74 73 20 |xample, |objects |
|00001920| 74 68 61 74 20 74 68 65 | 20 70 6c 61 79 65 72 20 |that the| player |
|00001930| 63 61 6e 27 74 20 70 69 | 63 6b 20 75 70 20 28 73 |can't pi|ck up (s|
|00001940| 75 63 68 20 61 73 20 70 | 68 6f 6e 65 20 62 6f 6f |uch as p|hone boo|
|00001950| 74 68 73 20 61 6e 64 0d | 0a 61 6e 76 69 6c 73 29 |ths and.|.anvils)|
|00001960| 20 72 65 73 70 6f 6e 64 | 20 77 69 74 68 20 61 20 | respond| with a |
|00001970| 73 69 6d 70 6c 65 20 60 | 60 59 6f 75 20 63 61 6e |simple `|`You can|
|00001980| 27 74 20 68 61 76 65 20 | 74 68 61 74 22 20 74 6f |'t have |that" to|
|00001990| 20 61 20 60 60 74 61 6b | 65 22 0d 0a 63 6f 6d 6d | a ``tak|e"..comm|
|000019a0| 61 6e 64 2c 20 77 68 65 | 72 65 61 73 20 6f 62 6a |and, whe|reas obj|
|000019b0| 65 63 74 73 20 74 68 61 | 74 20 63 61 6e 20 62 65 |ects tha|t can be|
|000019c0| 20 63 61 72 72 69 65 64 | 20 77 69 6c 6c 20 6d 6f | carried| will mo|
|000019d0| 76 65 20 74 68 65 6d 73 | 65 6c 76 65 73 0d 0a 69 |ve thems|elves..i|
|000019e0| 6e 74 6f 20 74 68 65 20 | 70 6c 61 79 65 72 27 73 |nto the |player's|
|000019f0| 20 69 6e 76 65 6e 74 6f | 72 79 20 6c 69 73 74 2e | invento|ry list.|
|00001a00| 20 20 54 68 65 20 62 61 | 73 69 63 20 61 64 76 65 | The ba|sic adve|
|00001a10| 6e 74 75 72 65 20 66 69 | 6c 65 20 7b 5c 74 74 20 |nture fi|le {\tt |
|00001a20| 5e 7b 61 64 76 2e 74 7d | 7d 0d 0a 64 65 66 69 6e |^{adv.t}|}..defin|
|00001a30| 65 73 20 61 20 6c 61 72 | 67 65 20 6e 75 6d 62 65 |es a lar|ge numbe|
|00001a40| 72 20 6f 66 20 62 61 73 | 69 63 20 63 6c 61 73 73 |r of bas|ic class|
|00001a50| 65 73 2c 20 62 75 74 20 | 74 68 65 20 72 65 61 6c |es, but |the real|
|00001a60| 20 70 6f 77 65 72 20 6f | 66 20 54 41 44 53 20 69 | power o|f TADS i|
|00001a70| 73 20 74 68 65 0d 0a 61 | 62 69 6c 69 74 79 20 74 |s the..a|bility t|
|00001a80| 6f 20 61 64 64 20 63 6c | 61 73 73 65 73 20 6f 66 |o add cl|asses of|
|00001a90| 20 79 6f 75 72 20 6f 77 | 6e 2e 0d 0a 0d 0a 0d 0a | your ow|n.......|
|00001aa0| 5c 6d 69 6e 6f 72 73 65 | 63 74 69 6f 6e 7b 54 41 |\minorse|ction{TA|
|00001ab0| 44 53 20 61 6e 64 20 6f | 74 68 65 72 20 4f 62 6a |DS and o|ther Obj|
|00001ac0| 65 63 74 2d 4f 72 69 65 | 6e 74 65 64 20 4c 61 6e |ect-Orie|nted Lan|
|00001ad0| 67 75 61 67 65 73 7d 0d | 0a 0d 0a 55 73 65 72 73 |guages}.|...Users|
|00001ae0| 20 6f 66 20 6f 74 68 65 | 72 20 6c 61 6e 67 75 61 | of othe|r langua|
|00001af0| 67 65 73 20 74 68 61 74 | 20 68 61 76 65 20 6f 62 |ges that| have ob|
|00001b00| 6a 65 63 74 2d 6f 72 69 | 65 6e 74 65 64 20 66 65 |ject-ori|ented fe|
|00001b10| 61 74 75 72 65 73 2c 20 | 73 75 63 68 0d 0a 61 73 |atures, |such..as|
|00001b20| 20 43 2b 2b 20 6f 72 20 | 53 6d 61 6c 6c 74 61 6c | C++ or |Smalltal|
|00001b30| 6b 2c 20 77 69 6c 6c 20 | 66 69 6e 64 20 74 68 61 |k, will |find tha|
|00001b40| 74 20 54 41 44 53 20 68 | 61 73 20 61 20 73 6c 69 |t TADS h|as a sli|
|00001b50| 67 68 74 6c 79 20 64 69 | 66 66 65 72 65 6e 74 0d |ghtly di|fferent.|
|00001b60| 0a 61 70 70 72 6f 61 63 | 68 20 74 6f 20 6f 62 6a |.approac|h to obj|
|00001b70| 65 63 74 2d 6f 72 69 65 | 6e 74 65 64 20 70 72 6f |ect-orie|nted pro|
|00001b80| 67 72 61 6d 6d 69 6e 67 | 2e 20 20 49 6e 20 70 61 |gramming|. In pa|
|00001b90| 72 74 69 63 75 6c 61 72 | 2c 20 0d 0a 54 41 44 53 |rticular|, ..TADS|
|00001ba0| 20 6d 61 6b 65 73 20 6d | 75 63 68 20 6c 65 73 73 | makes m|uch less|
|00001bb0| 20 6f 66 20 61 20 64 69 | 73 74 69 6e 63 74 69 6f | of a di|stinctio|
|00001bc0| 6e 20 62 65 74 77 65 65 | 6e 20 63 6c 61 73 73 65 |n betwee|n classe|
|00001bd0| 73 20 61 6e 64 20 6f 62 | 6a 65 63 74 73 0d 0a 74 |s and ob|jects..t|
|00001be0| 68 61 6e 20 6f 74 68 65 | 72 20 6c 61 6e 67 75 61 |han othe|r langua|
|00001bf0| 67 65 73 2e 0d 0a 0d 0a | 49 6e 20 43 2b 2b 20 61 |ges.....|In C++ a|
|00001c00| 6e 64 20 53 6d 61 6c 6c | 74 61 6c 6b 2c 20 61 20 |nd Small|talk, a |
|00001c10| 63 6c 61 73 73 20 69 73 | 20 61 20 74 65 6d 70 6c |class is| a templ|
|00001c20| 61 74 65 20 74 68 61 74 | 20 73 70 65 63 69 66 69 |ate that| specifi|
|00001c30| 65 73 20 74 68 65 0d 0a | 64 61 74 61 20 74 79 70 |es the..|data typ|
|00001c40| 65 73 20 73 74 6f 72 65 | 64 20 62 79 20 6d 65 6d |es store|d by mem|
|00001c50| 62 65 72 73 20 6f 66 20 | 74 68 65 20 63 6c 61 73 |bers of |the clas|
|00001c60| 73 2c 20 62 75 74 20 6f | 6e 6c 79 20 61 6e 20 6f |s, but o|nly an o|
|00001c70| 62 6a 65 63 74 0d 0a 61 | 63 74 75 61 6c 6c 79 20 |bject..a|ctually |
|00001c80| 73 74 6f 72 65 73 20 76 | 61 6c 75 65 73 20 66 6f |stores v|alues fo|
|00001c90| 72 20 74 68 65 20 64 61 | 74 61 2e 20 20 28 54 68 |r the da|ta. (Th|
|00001ca0| 69 73 20 69 73 20 61 6e | 61 6c 6f 67 6f 75 73 20 |is is an|alogous |
|00001cb0| 74 6f 0d 0a 74 68 65 20 | 64 69 73 74 69 6e 63 74 |to..the |distinct|
|00001cc0| 69 6f 6e 20 62 65 74 77 | 65 65 6e 20 61 20 73 74 |ion betw|een a st|
|00001cd0| 72 75 63 74 75 72 65 20 | 61 6e 64 20 69 6e 73 74 |ructure |and inst|
|00001ce0| 61 6e 63 65 73 20 6f 66 | 20 74 68 65 20 73 74 72 |ances of| the str|
|00001cf0| 75 63 74 75 72 65 0d 0a | 69 6e 20 61 20 6c 61 6e |ucture..|in a lan|
|00001d00| 67 75 61 67 65 20 73 75 | 63 68 20 61 73 20 43 20 |guage su|ch as C |
|00001d10| 6f 72 20 50 61 73 63 61 | 6c 3a 20 20 74 68 65 20 |or Pasca|l: the |
|00001d20| 73 74 72 75 63 74 75 72 | 65 20 64 65 66 69 6e 65 |structur|e define|
|00001d30| 73 20 74 68 65 0d 0a 6c | 61 79 6f 75 74 20 6f 66 |s the..l|ayout of|
|00001d40| 20 64 61 74 61 2c 20 62 | 75 74 20 6f 6e 6c 79 20 | data, b|ut only |
|00001d50| 61 6e 20 69 6e 73 74 61 | 6e 63 65 20 6f 66 20 74 |an insta|nce of t|
|00001d60| 68 65 20 73 74 72 75 63 | 74 75 72 65 20 61 63 74 |he struc|ture act|
|00001d70| 75 61 6c 6c 79 0d 0a 63 | 6f 6e 74 61 69 6e 73 20 |ually..c|ontains |
|00001d80| 61 6e 79 20 64 61 74 61 | 2e 29 20 20 54 68 65 20 |any data|.) The |
|00001d90| 69 6e 68 65 72 69 74 61 | 6e 63 65 20 73 74 72 75 |inherita|nce stru|
|00001da0| 63 74 75 72 65 20 70 65 | 72 74 61 69 6e 73 20 74 |cture pe|rtains t|
|00001db0| 6f 20 74 68 65 0d 0a 63 | 6c 61 73 73 65 73 3b 20 |o the..c|lasses; |
|00001dc0| 61 6e 20 6f 62 6a 65 63 | 74 20 69 73 20 61 6e 20 |an objec|t is an |
|00001dd0| 69 6e 73 74 61 6e 63 65 | 20 6f 66 20 61 20 70 61 |instance| of a pa|
|00001de0| 72 74 69 63 75 6c 61 72 | 20 63 6c 61 73 73 2c 20 |rticular| class, |
|00001df0| 73 6f 20 6f 6e 6c 79 0d | 0a 6d 65 74 68 6f 64 73 |so only.|.methods|
|00001e00| 20 61 6e 64 20 60 60 73 | 6c 6f 74 73 27 27 20 66 | and ``s|lots'' f|
|00001e10| 6f 72 20 64 61 74 61 20 | 63 61 6e 20 62 65 20 69 |or data |can be i|
|00001e20| 6e 68 65 72 69 74 65 64 | 2d 2d 2d 76 61 6c 75 65 |nherited|---value|
|00001e30| 73 20 66 6f 72 0d 0a 64 | 61 74 61 20 69 74 65 6d |s for..d|ata item|
|00001e40| 73 20 61 72 65 20 6e 6f | 74 20 74 68 65 6d 73 65 |s are no|t themse|
|00001e50| 6c 76 65 73 20 69 6e 68 | 65 72 69 74 65 64 2e 0d |lves inh|erited..|
|00001e60| 0a 0d 0a 49 6e 20 54 41 | 44 53 2c 20 74 68 65 72 |...In TA|DS, ther|
|00001e70| 65 20 69 73 20 6e 6f 20 | 64 69 73 74 69 6e 63 74 |e is no |distinct|
|00001e80| 69 6f 6e 20 62 65 74 77 | 65 65 6e 20 63 6c 61 73 |ion betw|een clas|
|00001e90| 73 65 73 20 61 6e 64 20 | 69 6e 73 74 61 6e 63 65 |ses and |instance|
|00001ea0| 73 0d 0a 6f 66 20 63 6c | 61 73 73 65 73 2c 20 69 |s..of cl|asses, i|
|00001eb0| 6e 20 74 68 61 74 20 61 | 20 63 6c 61 73 73 20 69 |n that a| class i|
|00001ec0| 73 20 61 6c 73 6f 20 61 | 6e 20 6f 62 6a 65 63 74 |s also a|n object|
|00001ed0| 2e 20 20 48 65 6e 63 65 | 2c 20 64 61 74 61 20 76 |. Hence|, data v|
|00001ee0| 61 6c 75 65 73 0d 0a 61 | 73 20 77 65 6c 6c 20 61 |alues..a|s well a|
|00001ef0| 73 20 6d 65 74 68 6f 64 | 73 20 63 61 6e 20 62 65 |s method|s can be|
|00001f00| 20 69 6e 68 65 72 69 74 | 65 64 20 66 72 6f 6d 20 | inherit|ed from |
|00001f10| 61 20 70 61 72 65 6e 74 | 20 6f 62 6a 65 63 74 2e |a parent| object.|
|00001f20| 0d 0a 49 6e 20 54 41 44 | 53 2c 20 74 68 65 20 6f |..In TAD|S, the o|
|00001f30| 6e 6c 79 20 64 69 73 74 | 69 6e 63 74 69 6f 6e 20 |nly dist|inction |
|00001f40| 62 65 74 77 65 65 6e 20 | 61 20 63 6c 61 73 73 20 |between |a class |
|00001f50| 61 6e 64 20 61 20 6e 6f | 72 6d 61 6c 20 6f 62 6a |and a no|rmal obj|
|00001f60| 65 63 74 0d 0a 69 73 20 | 74 68 61 74 20 61 20 63 |ect..is |that a c|
|00001f70| 6c 61 73 73 20 6f 62 6a | 65 63 74 20 69 73 20 69 |lass obj|ect is i|
|00001f80| 67 6e 6f 72 65 64 20 62 | 79 20 74 68 65 20 70 6c |gnored b|y the pl|
|00001f90| 61 79 65 72 20 63 6f 6d | 6d 61 6e 64 20 70 61 72 |ayer com|mand par|
|00001fa0| 73 65 72 2e 0d 0a 0d 0a | 54 68 69 73 20 64 69 66 |ser.....|This dif|
|00001fb0| 66 65 72 65 6e 74 20 61 | 70 70 72 6f 61 63 68 20 |ferent a|pproach |
|00001fc0| 6c 65 61 64 73 20 74 6f | 20 61 20 64 69 66 66 65 |leads to| a diffe|
|00001fd0| 72 65 6e 74 20 73 74 79 | 6c 65 20 6f 66 20 70 72 |rent sty|le of pr|
|00001fe0| 6f 67 72 61 6d 6d 69 6e | 67 2e 0d 0a 41 20 54 41 |ogrammin|g...A TA|
|00001ff0| 44 53 20 70 72 6f 67 72 | 61 6d 20 63 6f 6e 73 69 |DS progr|am consi|
|00002000| 73 74 73 20 6d 6f 73 74 | 6c 79 20 6f 66 20 64 65 |sts most|ly of de|
|00002010| 66 69 6e 69 74 69 6f 6e | 73 20 6f 66 20 6f 62 6a |finition|s of obj|
|00002020| 65 63 74 73 20 28 69 6e | 73 74 61 6e 63 65 73 0d |ects (in|stances.|
|00002030| 0a 6f 66 20 63 6c 61 73 | 73 65 73 29 2e 20 20 41 |.of clas|ses). A|
|00002040| 6c 6c 20 6f 66 20 74 68 | 65 20 69 6e 73 74 61 6e |ll of th|e instan|
|00002050| 63 65 73 20 61 72 65 20 | 73 70 65 63 69 66 69 63 |ces are |specific|
|00002060| 61 6c 6c 79 20 64 65 66 | 69 6e 65 64 2c 20 77 69 |ally def|ined, wi|
|00002070| 74 68 0d 0a 76 61 6c 75 | 65 73 20 66 6f 72 20 70 |th..valu|es for p|
|00002080| 72 6f 70 65 72 74 69 65 | 73 2c 20 69 6e 20 74 68 |ropertie|s, in th|
|00002090| 65 20 67 61 6d 65 20 70 | 72 6f 67 72 61 6d 2e 20 |e game p|rogram. |
|000020a0| 20 49 6e 20 63 6f 6e 74 | 72 61 73 74 2c 20 61 20 | In cont|rast, a |
|000020b0| 43 2b 2b 0d 0a 6f 72 20 | 53 6d 61 6c 6c 74 61 6c |C++..or |Smalltal|
|000020c0| 6b 20 70 72 6f 67 72 61 | 6d 20 75 73 75 61 6c 6c |k progra|m usuall|
|000020d0| 79 20 64 65 66 69 6e 65 | 73 20 6d 6f 73 74 6c 79 |y define|s mostly|
|000020e0| 20 63 6c 61 73 73 65 73 | 2c 20 61 6e 64 20 63 72 | classes|, and cr|
|000020f0| 65 61 74 65 73 0d 0a 69 | 6e 73 74 61 6e 63 65 73 |eates..i|nstances|
|00002100| 20 61 74 20 72 75 6e 2d | 74 69 6d 65 2e 0d 0a 0d | at run-|time....|
|00002110| 0a 5c 65 6e 64 63 68 61 | 70 74 65 72 0d 0a 0d 0a |.\endcha|pter....|
|00002120| 54 68 65 20 6e 6f 62 6c | 65 73 74 20 66 75 6e 63 |The nobl|est func|
|00002130| 74 69 6f 6e 20 6f 66 20 | 61 6e 20 6f 62 6a 65 63 |tion of |an objec|
|00002140| 74 20 69 73 20 74 6f 20 | 62 65 20 63 6f 6e 74 65 |t is to |be conte|
|00002150| 6d 70 6c 61 74 65 64 2e | 0d 0a 5c 61 75 74 68 6f |mplated.|..\autho|
|00002160| 72 20 4d 49 47 55 45 4c | 20 44 45 20 55 4e 41 4d |r MIGUEL| DE UNAM|
|00002170| 55 4e 4f 2c 20 7b 5c 73 | 6c 20 4d 69 73 74 5c 2f |UNO, {\s|l Mist\/|
|00002180| 7d 20 28 31 39 31 34 29 | 0d 0a 0d 0a 5c 65 6a 65 |} (1914)|....\eje|
|00002190| 63 74 0d 0a | |ct.. | |
+--------+-------------------------+-------------------------+--------+--------+